package com.qianbei.user;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Request;
import com.bumptech.glide.Glide;
import com.qianbei.R;
import com.qianbei.common.base.BaseActivity;
import com.qianbei.common.net.control.ServerControl;
import com.qianbei.common.net.control.ServerResult;
import com.qianbei.common.net.view.ProgressDialog;
import com.qianbei.common.util.ConstantValue;
import com.qianbei.common.utilis.img.CropCircleTransformation;
import com.qianbei.user.model.UserMode;

/**
 * 晚辈简介
 *
 * @author jiaowenzheng
 *
 * 从聊天会话中点击头晚辈头像跳转该页面
 * Created by user on 16/8/22.
 */
public class JuniorIntroductionActivity extends BaseActivity {

    private TextView mUserNameTv;
    private TextView mLocationTv;
    private TextView mDescriptionTv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_junior_introduction);

        setTitle(R.string.user_title);

        mUserNameTv = (TextView) findViewById(R.id.tv_user_name);
        mLocationTv = (TextView) findViewById(R.id.tv_location);
        mDescriptionTv = (TextView) findViewById(R.id.tv_personal_description);


        String id = getIntent().getStringExtra(ConstantValue.ID_KEY);
        if (!TextUtils.isEmpty(id)) {
            getUserInfoById(id);
//            mIcon.loadBuddyAvatar(id);
        }

    }


    /**
     * 根据用户ID获取用户信息
     *
     * @param id
     */
    public void getUserInfoById(String id) {

        final ServerControl sc = new ServerControl(Request.Method.GET, String.format(GET_USER_INFO_BY_ID_URL, id)+"?");
        sc.serverListener = new ServerControl.ServerListener() {
            @Override
            public void serverFinish(ServerResult sr) {

                if (sr.isContinue) {

                    UserMode userInfo = JSON.parseObject(
                            sr.bodyData.optJSONObject("user_info").toString(), UserMode.class);

                    if (userInfo != null){

                        mUserNameTv.setText(userInfo.name);
                        mLocationTv.setText(userInfo.city);
                        mDescriptionTv.setText(userInfo.career);

//                        Glide.with(JuniorIntroductionActivity.this)
//                                .load(URL + userInfo.face)
//                                .placeholder(R.drawable.ic_launcher)
//                                .bitmapTransform(new CropCircleTransformation(JuniorIntroductionActivity.this))
                    }

                }
            }
        };

        new ProgressDialog(this).startControl(sc);
    }


}
